//---------------------------------------------------------------------
//  This file is part of the Background Motion solution.
// 
//  Copyright (C) Mindscape (TM).  All rights reserved.
//  http://www.mindscape.co.nz
// 
//  THIS CODE AND INFORMATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY
//  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//  PARTICULAR PURPOSE.
//---------------------------------------------------------------------

using System.Configuration;
using System.Xml;

namespace Mindscape.BackgroundMotion.Website.Infrastructure
{
  public class SmtpMailSenderConfigSectionHandler : IConfigurationSectionHandler
  {
    #region IConfigurationSectionHandler Members

    /// <summary>
    /// Creates a configuration section handler.
    /// </summary>
    /// <param name="parent"></param>
    /// <param name="configContext">Configuration context object.</param>
    /// <param name="section"></param>
    /// <returns>The created section handler object.</returns>
    public object Create(object parent, object configContext, XmlNode section)
    {
      SmtpMailSenderConfig config = new SmtpMailSenderConfig();

      if (section.SelectSingleNode("Host") != null)
      {
        config.Host = section.SelectSingleNode("Host").InnerText;
      }

      if (section.SelectSingleNode("RecipientAddress") != null)
      {
        config.RecipientAddress = section.SelectSingleNode("RecipientAddress").InnerText;
      }

      if (section.SelectSingleNode("DeliverEmail") != null)
      {
        config.DeliverEmail = bool.Parse(section.SelectSingleNode("DeliverEmail").InnerText);
      }

      return config;
    }

    #endregion
  }
}
